package org.dormi.learn.product.port.persist.material;

import org.dormi.learn.primitive.Measure;
import org.dormi.learn.product.domain.material.entity.Material;
import org.dormi.learn.product.domain.material.entity.MaterialLogistics;
import org.dormi.learn.utils.JsonSerializer;

/**
 * entity - po之间的转换
 * 不允许 public
 *
 * @author : dormi330
 * @version : 1.0
 */
class ConverterOld {

    static MaterialPO material_toPO(Material eo) {

        /* === 相同名称类型字段拷贝 === */
        /* === 相同名称类型字段拷贝 === */
        /* === 相同名称类型字段拷贝 === */
        MaterialPO po = JsonSerializer.objectCopy(eo, MaterialPO.class);

        /* === map -> json === */
        /* === map -> json === */
        /* === map -> json === */
        po.setExtJson(eo.mapToJson());

        /* === 其他字段拷贝 === */
        /* === 其他字段拷贝 === */
        /* === 其他字段拷贝 === */
        if (eo.getPhysicalForm() != null) {
            po.setFormCode(eo.getPhysicalForm().getCode());
        }

        if (eo.getLogistics() != null) {
            MaterialLogistics l = eo.getLogistics();
            //
            po.setLength(l.getLength());
            po.setWidth(l.getWidth());
            po.setHeigth(l.getHeigth());
            po.setLengthUnitCode(l.getLengthUnit().getCode());
            //
            po.setNetWeight(l.getNetWeight());
            po.setGrossWeight(l.getGrossWeight());
            po.setWeightUnitCode(l.getWeightUnit().getCode());
        }

        if (eo.getValidityTime() != null) {
            Measure m = eo.getValidityTime();
            po.setValidityTimeLength(m.getQuantity());
            po.setValidityUnitCode(m.getUnit().getCode());
        }

        if (eo.getMinSKU() != null) {
            po.setMinSkuCode(eo.getMinSKU().getCode());
        }

        if (eo.getTrackingType() != null) {
            po.setTrackingTypeCode(eo.getTrackingType().getCode());
        }

        return po;
    }

    static Material material_toPO(MaterialPO src) {
        return null;
    }

}
